var e = require;
var t = module;
var n = exports;
var o,
    i =
    (this && this.__extends) ||
    ((o = function(e, t) {
            return (o =
                Object.setPrototypeOf ||
                ({ __proto__: [] }
                    instanceof Array &&
                    function(e, t) {
                        e.__proto__ = t;
                    }) ||
                function(e, t) {
                    for (var n in t) Object.prototype.hasOwnProperty.call(t, n) && (e[n] = t[n]);
                })(e, t);
        }),
        function(e, t) {
            function n() {
                this.constructor = e;
            }
            o(e, t), (e.prototype = null === t ? Object.create(t) : ((n.prototype = t.prototype), new n()));
        }),
    r =
    (this && this.__decorate) ||
    function(e, t, n, o) {
        var i,
            r = arguments.length,
            a = r < 3 ? t : null === o ? (o = Object.getOwnPropertyDescriptor(t, n)) : o;
        if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) a = Reflect.decorate(e, t, n, o);
        else
            for (var s = e.length - 1; 0 <= s; s--)
                (i = e[s]) && (a = (r < 3 ? i(a) : 3 < r ? i(t, n, a) : i(t, n)) || a);
        return 3 < r && a && Object.defineProperty(t, n, a), a;
    };
Object.defineProperty(n, "__esModule", { value: !0 });
var a,
    s = e("index"),
    c = e("common"),
    l = e("platform-const"),
    u = e("wechat-ad"),
    p = e("player-info"),
    h = cc._decorator,
    d = h.ccclass,
    f = h.property,
    t = h.requireComponent,
    e = h.disallowMultiple,
    h = h.menu,
    h =
    ((a = cc.Component),
        i(m, a),
        (m.prototype.onLoad = function() {
            this.node.on("click", this.onClick, this), s.platform.preloadVideo(u.VideoUnit[this.videoDuration]);
        }),
        (m.prototype.onClick = function(e) {
            var t,
                n,
                o = this;
            (e && !e.interactable) ||
            null == this.onWatchEndEvent ||
                (null != this.beforeWatchCheckHandler && !this.beforeWatchCheckHandler()) ||
                ((t = c.tempDisableButton(this.node, 1)),
                    (n = p.playerInfo.getGameType() === p.gameType.nomal ? "main" : "challenge"),
                    s.platform
                    .doWatchAD({
                        videoSource: this.videoSource,
                        videoDuration: this.videoDuration,
                        sequenceInfo: null,
                        item: n
                    })
                    .then(function() {
                        t(), o.onWatchEndEvent && cc.Component.EventHandler.emitEvents([o.onWatchEndEvent], e);
                    })
                    .catch(function(e) {
                        t(), e == l.VideoFailCode.NO_AD && s.showToast("暂无视频可看");
                    }));
        }),
        (m.prototype.setBeforeWatchCheckHandler = function(e) {
            this.beforeWatchCheckHandler = e;
        }),
        r([f(cc.String)], m.prototype, "videoSource", void 0),
        r([f({ type: cc.Enum(u.VideoUnitType) })], m.prototype, "videoDuration", void 0),
        r([f(cc.Component.EventHandler)], m.prototype, "onWatchEndEvent", void 0),
        r([d, t(cc.Button), e, h("button/VideoButton")], m));

function m() {
    var e = (null !== a && a.apply(this, arguments)) || this;
    return (
        (e.videoSource = ""),
        (e.videoDuration = u.VideoUnitType.MEDIUM),
        (e.onWatchEndEvent = null),
        (e.beforeWatchCheckHandler = null),
        e
    );
}
n.default = h;